/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 019. 最多删除一个字符得到回文
 * @author: WXY
 * @create: 2022-12-14 18:23
 * @Version 1.0
 **/


public class Num_offer2_019_validPalindrome {
    public static boolean validPalindrome(String s) {
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            if (s.charAt(left) == s.charAt(right)) {
                left++;
                right--;
            } else {
                return valid(s, left + 1, right) || valid(s, left, right - 1);
            }
        }
        return true;
    }

    private static boolean valid(String s, int left, int right) {
        while (left < right) {
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            } else {
                left++;
                right--;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        String s = "abcbva";
        boolean ans = validPalindrome(s);
        System.out.println(ans);

    }
}
